package main

import "fmt"

// 产品接口
type Laptop interface {
	Compute()
}

type Phone interface {
	Call()
}

// 产品实现：Apple 系列
type AppleLaptop struct{}

func (a *AppleLaptop) Compute() {
	fmt.Println("Computing with Apple Laptop.")
}

type ApplePhone struct{}

func (a *ApplePhone) Call() {
	fmt.Println("Calling with Apple Phone.")
}

// 产品实现：Dell 系列
type DellLaptop struct{}

func (d *DellLaptop) Compute() {
	fmt.Println("Computing with Dell Laptop.")
}

type DellPhone struct{}

func (d *DellPhone) Call() {
	fmt.Println("Calling with Dell Phone.")
}

// 抽象工厂接口
type ElectronicsFactory interface {
	CreateLaptop() Laptop
	CreatePhone() Phone
}

// 具体工厂：Apple 工厂
type AppleFactory struct{}

func (af *AppleFactory) CreateLaptop() Laptop {
	return &AppleLaptop{}
}
func (af *AppleFactory) CreatePhone() Phone {
	return &ApplePhone{}
}

// 具体工厂：Dell 工厂
type DellFactory struct{}

func (df *DellFactory) CreateLaptop() Laptop {
	return &DellLaptop{}
}
func (df *DellFactory) CreatePhone() Phone {
	return &DellPhone{}
}

func main() {
	appleFactory := &AppleFactory{}
	dellFactory := &DellFactory{}

	appleLaptop := appleFactory.CreateLaptop()
	applePhone := appleFactory.CreatePhone()

	dellLaptop := dellFactory.CreateLaptop()
	dellPhone := dellFactory.CreatePhone()

	appleLaptop.Compute() // 输出: Computing with Apple Laptop.
	applePhone.Call()     // 输出: Calling with Apple Phone.

	dellLaptop.Compute() // 输出: Computing with Dell Laptop.
	dellPhone.Call()     // 输出: Calling with Dell Phone.
}
